package com.mouse.controller.user;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.mouse.common.lang.Result;
import com.mouse.entity.*;
import com.mouse.entity.vo.GeneAlleleVO;
import com.mouse.mapper.*;
import com.mouse.service.GeneAlleleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author godson
 * @since 2022-08-07
 */
@RestController
@RequestMapping("/gene-allele")
public class GeneAlleleController {
    @Autowired
    GeneAlleleService geneAlleleService;

    @Autowired
    GeneCategoryMapper geneCategoryMapper;

    @Autowired
    private DiseaseMapper diseaseMapper;

    @Autowired
    private DoubleAllelesMapper doubleAllelesMapper;

    @Autowired
    private GeneCompositionMapper geneCompositionMapper;

    @Autowired
    private PhenotypeMapper phenotypeMapper;

    @Autowired
    private ReferenceMapper referenceMapper;




    @GetMapping("/get/")
    public Result select(@Validated @RequestParam String key, @RequestParam String value, @RequestParam(defaultValue = "1") int pageNum, @RequestParam(defaultValue = "10") int pageSize ) {
        IPage<GeneAllele> page = new Page<>(pageNum, pageSize);
        IPage<GeneAllele> info = geneAlleleService.getInfoByMap(page, key, value);
        if (info.getSize() == 0) {
            return Result.fail("无对应记录");
        }
        return Result.succ(info);
    }

//    @GetMapping("/relevant/{aid}")
//    public Result getByAid(@PathVariable(name = "aid") Long aid){
//        GeneAlleleDTO geneAlleleDTO = new GeneAlleleDTO();
//        geneAlleleDTO.setGeneCategories(geneCategoryMapper.getGeneCategoryByAid(aid));
//        geneAlleleDTO.setDoubleAlleles(doubleAllelesMapper.getDoubleAllelesByAid(aid));
//        geneAlleleDTO.setGeneCompositions(geneCompositionMapper.getGeneCompositionByAid(aid));
//        geneAlleleDTO.setDiseases(diseaseMapper.getDiseaseByAid(aid));
//        geneAlleleDTO.setPhenotypes(phenotypeMapper.getPhenotypeByAid(aid));
//        geneAlleleDTO.setReferences(referenceMapper.getReferenceByAid(aid));
//        return Result.succ(geneAlleleDTO);
//    }

    @GetMapping("/info/{aid}")
    public Result getInfo(@PathVariable(name="aid") Long aid){
        GeneAllele allele = geneAlleleService.getById(aid);
        GeneAlleleVO geneAlleleVO = geneAlleleService.getGeneAlleleVO(allele);
        return Result.succ(geneAlleleVO);

    }

//    @GetMapping("/gene-composition/{aid}/{currentPage}/{pageSize}")
//    public Result getGeneCompositionByAid(@PathVariable(name = "aid") Long aid,
//                                          @PathVariable Integer currentPage,
//                                          @PathVariable Integer pageSize) {
//        Page<GeneComposition> page = new Page<>(currentPage, pageSize);
//        Page<GeneComposition> pages = geneCompositionMapper.getGeneCompositionByAid(page, aid);
//        return Result.succ(pages);
//    }
//
//
//    @GetMapping("/reference/{aid}/{currentPage}/{pageSize}")
//    public Result getReferenceByAid(@PathVariable(name = "aid") Long aid,
//                                    @PathVariable Integer currentPage,
//                                    @PathVariable Integer pageSize) {
//        Page<Reference> page = new Page<>(currentPage, pageSize);
//        Page<Reference> pages = referenceMapper.getReferenceByAid(page, aid);
//        return Result.succ(pages);
//    }
//
//    @GetMapping("/phenotype/{aid}/{currentPage}/{pageSize}")
//    public Result getPhenotypeByAid(@PathVariable(name = "aid") Long aid,
//                                    @PathVariable Integer currentPage,
//                                    @PathVariable Integer pageSize) {
//        Page<Phenotype> page = new Page<>(currentPage, pageSize);
//        Page<Phenotype> pages = phenotypeMapper.getPhenotypeByAid(page, aid);
//        return Result.succ(pages);
//    }
//
//    @GetMapping("/gene-allele/{aid}/{currentPage}/{pageSize}")
//    public Result getDoubleAlleleByAid(@PathVariable(name = "aid") Long aid,
//                                       @PathVariable Integer currentPage,
//                                       @PathVariable Integer pageSize) {
//        Page<DoubleAlleles> page = new Page<>(currentPage, pageSize);
//        Page<DoubleAlleles> pages = doubleAllelesMapper.getDoubleAllelesByAid(page, aid);
//        return Result.succ(pages);
//    }
//
//    @GetMapping("/disease/{aid}/{currentPage}/{pageSize}")
//    public Result getDiseaseByAid(@PathVariable(name = "aid") Long aid,
//                                  @PathVariable Integer currentPage,
//                                  @PathVariable Integer pageSize) {
//        Page<Disease> page = new Page<>(currentPage, pageSize);
//        Page<Disease> pages = diseaseMapper.getDiseaseByAid(page, aid);
//        return Result.succ(pages);
//    }
//
//    @GetMapping("/geneCategory/{aid}/{currentPage}/{pageSize}")
//    public Result getGeneCategoryByAid(@PathVariable(name = "aid") Long aid,
//                                       @PathVariable Integer currentPage,
//                                       @PathVariable Integer pageSize) {
//        Page<GeneCategory> page = new Page<>(currentPage, pageSize);
//        Page<GeneCategory> pages = geneCategoryMapper.getGeneCategoryByAid(page, aid);
//        return Result.succ(pages);
//    }


}
